﻿using System;
using ACompany.OrderProcessing.Presentation.Customer;

public partial class Customer_CustomerDetail : System.Web.UI.UserControl, ICustomerView
{
    private CustomerPresenter _presenter;

    private void Page_Init(object sender, EventArgs e)
    {
        _presenter = new CustomerPresenter(this);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            _presenter.Display();
        }

    }


    protected void btnCancelEditCustomer_Click(object sender, EventArgs e)
    {
        Response.Redirect("CustomerList.aspx");
    }
    protected void btnSaveCustomer_Click(object sender, EventArgs e)
    {
        _presenter.SaveCustomer();
    }

    public void ErrorMessage(string message)
    {
        if (string.IsNullOrEmpty(message))
        {
            pnlError.Visible = false;
            return;
        }
        pnlError.Visible = true;
        this.litErrorMessage.Text = message.Replace(Environment.NewLine, "<br/>");
    }

    public void InfoMessage(string message)
    {
        if (string.IsNullOrEmpty(message))
        {
            pnlInfo.Visible = false;
            return;
        }
        pnlInfo.Visible = true;
        this.litInfoMessage.Text = message.Replace(Environment.NewLine, "<br/>");
    }

    public void ViewTitle(string title)
    {
        litTitle.Text = title;
    }

    #region propperties

    public Guid CustomerId
    {
        get
        {
            Guid SelectedCustomerId;
            if (string.IsNullOrEmpty(Request.QueryString["CustomerId"]))
            {
                SelectedCustomerId = Guid.Empty;
            }
            else
            {
                SelectedCustomerId = new Guid(Request.QueryString["CustomerId"]);
            }

            return SelectedCustomerId;
        }
    }

    public string City
    {
        get { return this.txtCity.Text; }
        set { this.txtCity.Text = value; }
    }

    public string Country
    {
        get { return this.txtCountry.Text; }
        set { this.txtCountry.Text = value; }
    }

    public string Email
    {
        get { return this.txtEmail.Text; }
        set { this.txtEmail.Text = value; }
    }

    public string Name
    {
        get { return this.txtName.Text; }
        set { this.txtName.Text = value; }
    }

    public string PostCode
    {
        get { return this.txtPostCode.Text; }
        set { this.txtPostCode.Text = value; }
    }

    public string Street
    {
        get { return this.txtStreet.Text; }
        set { this.txtStreet.Text = value; }
    }
    public string SaveButtonText
    {
        set { btnSaveCustomer.Text = value; }
    }
    #endregion
}